<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 连接两字母单词得到的最长回文串 -->
    <script>
      var longes = function (words) {
        let hash = {},
          res = 0
        for (let i = 0; i < words.length; i++) {
          const revers = words[i][1] + words[i][0]
          if (hash[revers]) {
            res += 4
            hash[revers] -= 1
          } else {
            hash[words[i]] = (hash[words[i]] || 0) + 1
          }
        }
        for (let word in hash) {
          if (hash[word] && word[0] === word[1]) return res + 2
        }
        return res
      }
      console.log(longes(['lc', 'cl', 'gg']))
    </script>
  </body>
</html>
